import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import Pagination from './components/pagination.vue';
import { resetForm } from '@/until/globalFun';
import { parseTime, timestampToDate,getStatus } from '@/until/paramRou'
import { loadAppConfig, getConfig } from '@/until/globalFun';
import permissions from '@/until/permissions'


// 1. 在 Vue 实例化前加载配置
const initApp = async () => {

  try {
    // 阻塞执行，直到配置加载完成
    await loadAppConfig();
    Vue.prototype.$configURL = getConfig().serverUrl; // 生产 axios 请求地址
    Vue.prototype.$recordNum = getConfig().recordNum; // 生产 备案号
    Vue.prototype.$downUrl = getConfig().downUrl; // 生产 下载地址
    Vue.prototype.$isValidate = getConfig().isValidate; // 生产 是否需要验证码

    
    // Vue.prototype.$configURL = 'http://192.168.0.129:9999/'; // 本地
    Vue.prototype.resetForm = resetForm
    Vue.prototype.parseTime = parseTime
    Vue.prototype.timestampToDate = timestampToDate
    Vue.prototype.getStatus = getStatus
    Vue.config.productionTip = false


    Vue.component('pagination',Pagination)
    Vue.use(ElementUI)
    Vue.use(permissions)

    new Vue({
      router,
      store,
      render: h => h(App)
    }).$mount('#app')


  } catch (error) {
    
    // 处理配置加载失败的情况
    document.getElementById('app').innerHTML = `
      <div style="padding: 20px; color: red;">
        <h2>应用初始化失败</h2>
        <p>${error.message}</p>
        <button onclick="window.location.reload()">点击重试</button>
      </div>
    `;
  }


}


initApp()
